#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>

using namespace std;
void InsertSort(int* nums, int n)
{
	for (int i = 0; i < n - 1; i++)
	{
		int tmp = nums[i + 1];
		int end = i;
		while (end >= 0)
		{
			if (nums[end] > tmp)
			{
				nums[end + 1] = nums[end];
				--end;
			}
			else break;
		}
		nums[end + 1] = tmp;
	}
}
void ShellSort(int* a, int n)
{
	int gap = n;

	while (gap > 1)
	{
		gap = gap / 3 + 1;
		for (int i = 0; i < n - gap; i++)
		{
			int tmp = a[i + gap];
			int end = i;
			while (end >= 0)
			{
				if (a[end] > tmp)
				{
					a[end + gap] = a[end];
					end -= gap;
				}
				else break;
			}
			a[end + gap] = tmp;
		}
	}
}
void Print(int* a, int n)
{
	for (int i = 0; i < n; i++)
	{
		cout << a[i] << ' ';
	}
	cout << '\n';
}
void test1()
{
	int a[10] = { 6, 3, 45, 1, 34, 53, 2, 4, 1, 9 };
	InsertSort(a, 10);
	Print(a, 10);
}
void test2()
{
	int a[10] = { 6, 3, 45, 1, 34, 53, 2, 4, 1, 9 };
	ShellSort(a, 10);
	Print(a, 10);
}
void test3()
{
	int a[10] = { 6, 3, 45, 1, 34, 53, 2, 4, 1, 9 };
	Print(a, 10);
}
int main()
{
	test1();
	test2();
	return 0;
}